<template>
	<div class="partnerList">
		<div class="partnerList_top">
			<el-breadcrumb separator-class="el-icon-arrow-right" style="margin-top: 10px;">
				<el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
				<el-breadcrumb-item :to="{ path: '/stewardTeam' }">团队详情</el-breadcrumb-item>
				<el-breadcrumb-item>成员详情</el-breadcrumb-item>
			</el-breadcrumb>
		</div>
		<div class="partnerList_bottom">
			<div class="partnerList_bottom_new">
				<div class="partnerList_bottom_new_goods">
					<div class="partnerList_bottom_new_goods_screening">
						<!-- <span>卖场：</span>
                        <el-select
                          v-model="info.market_name"
                          clearable
                          @change="selectMarket"
                          filterable
						  disabled 
                          placeholder="卖场"
                        >
                          <el-option
                            v-for="item in marketList"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id"
                          >
                          </el-option>
                        </el-select> -->
						<div class="sidebarLeft item">
							<div style="margin-left: 20px">
								带单金额：<strong style="font-size: 18px">{{userData.amount}}</strong>
							</div>
							<div style="margin-left: 20px">
								带客数：<strong style="font-size: 18px">{{userData.num}}</strong>
							</div>
							<div style="margin-left: 20px">
								收益：<strong style="font-size: 18px">{{userData.commission}}</strong>
							</div>
						</div>
						<!-- <div class="item">
							<el-input v-model="keyword" placeholder="搜索"></el-input>
						</div>
						<div class="item">
							<button @click="handerSeach" class="searchBtn"><i class="el-icon-search"></i>搜索</button>
						</div> -->
					</div>
					<div class="subnav">
						<div class="itemBlock">
							<ul>
								<li>
									成员名称：<strong style="font-size: 18px">{{userData.nickname}}</strong>
								</li>
								<li>
									成员手机：<strong style="font-size: 18px">{{userData.mobile}}</strong>
								</li>
								<li>
									角色权限：<strong
										style="font-size: 18px">{{userData.type==1?'超级管家':userData.type==2?'超级政委':'精英管家'}}</strong>
								</li>
							</ul>
						</div>
						<div class="searchBlock">
							<span>订单类型：</span>
							<el-select
							  v-model="partner_type"
							  clearable
							  @change="selectOrder"
							  filterable
							  placeholder="订单类型"
							>
							  <el-option
							    v-for="item in orderList"
							    :key="item.id"
							    :label="item.name"
							    :value="item.id"
							  >
							  </el-option>
							</el-select>
							订单日期：
							<el-date-picker
							  style="margin-right: 20px"
							  clearable
							  v-model="valueTime"
							  :picker-options="pickerOptions"
							  type="daterange"
							  @change="selectTime"
							  range-separator="至"
							  start-placeholder="开始日期"
							  end-placeholder="结束日期"
							>
							</el-date-picker>
							<span>订单状态：</span>
							<el-select
							  v-model="order_status"
							  clearable
							  @change="selectStatus"
							  filterable
							  placeholder="订单类型"
							>
							  <el-option
							    v-for="item in orderStatus"
							    :key="item.id"
							    :label="item.name"
							    :value="item.id"
							  >
							  </el-option>
							</el-select>
							<div class="item" style="margin-left: 15px;">
								<el-input v-model="keyword" placeholder="搜索"></el-input>
							</div>
							<div class="item" style="margin-left: 15px;">
								 <el-button type="primary" @click="handerSeach" size="small">搜索</el-button>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="partnerList_table">

				<div class="partnerList_bottom_table">
					<table>
						<tr>
							<th></th>
							<th>订单号</th>
							<th>下单时间</th>
							<th>下单用户</th>
							<th>手机号</th>
							<th>数量</th>
							<th>总价</th>
							<th>定金</th>
							<th>订单类型</th>
							<th>订单状态</th>
							<th>佣金</th>
							<!-- <th>操作</th> -->
						</tr>
						<tr v-for="(v,i) in listData" :key="i">
							<td>
								<font class="checkbox" :class="{'check_active' : checkBoxAll.includes(i)}"
									@click="handlerCheckbox(i)"><i class="el-icon-check"></i></font>
							</td>
							<td>
								{{v.order_no}}
							</td>
							<td>
								{{formatDate(v.create_time)}}
							</td>
							<td>
								{{v.name}}
							</td>
							<td>{{v.mobile}}</td>
							<td>{{v.num}}</td>
							<td>{{v.price}}</td>
							<td>
								{{v.deposit_price}}
							</td>
							<td>{{v.buy_type==0?'普通':v.type==1?'拼团':'其他'}}</td>
							<td>{{v.status_des}}</td>
							<td>{{v.real_commission}}</td>
							<!-- <td>
								<button class="editor shelves" @click="deletes(v.steward_id,v.user_id)">成员详情</button>
							</td> -->
						</tr>
						<tr v-if="listData.length == 0">
							<td class="table_title" colspan="10">当前数据空空如也</td>
						</tr>
					</table>
					<div class="partnerList_bottom_page">
						<div class="partnerList_bottom_page_left">
							<div class="partnerList_bottom_page_left_checkAll" @click="handerCheckAll">
								<!-- <font class="checkbox" :class="{'check_active' : checkAll}"><i
										class="el-icon-check"></i></font> -->
							</div>
							<!-- <button class="partnerList_bottom_page_left_btn" @click="selectDel">删除</button> -->
						</div>
						<div class="partnerList_bottom_page_right">
							<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
								:current-page="page" :page-sizes="[10, 20, 30, 40]" :page-size="pageSize"
								layout="total, sizes, prev, pager, next, jumper" :total="total" background>
							</el-pagination>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
	import modal from 'ant-design-vue/lib/modal';
	import 'ant-design-vue/lib/table/style/css'; // 或者 ant-design-vue/lib/button/style/css 加载 css 文件
	import 'ant-design-vue/lib/modal/style/css'; // 或者 ant-design-vue/lib/button/style/css 加载 css 文件
	export default {
		components: {
			modal
		},
		data() {
			return {
				listData: [],
				keyword: '',
				input: '',
				checkAll: false,
				page: 1,
				pageSize: 20,
				pageSizes: 10,
				total: 0,
				checkBoxAll: [], // 选中的数据
				shelvesAlls: [],
				tableList: [],
				order_status: '', //订单状态
				visibleShow: false,
				merchantShow: false, //编辑窗口显示
				dialogVisible: false,
				fileList: [],
				title: '', //团队标题
				sub_title: '', //团队副标题
				steward_id: '', //团队id
				MadalTitle: '',
				activity_id: '', //活动id
				market_id: '', //卖场
				typeList: [{
						name: '超级管家',
						id: 1
					},
					{
						name: '超级政委',
						id: 2
					}
				], //活动列表
				activityKeyword: '', //活动搜索
				userData: {}, //用户详情
				choose_id: '', //选择的用户
				steward_id: '', //团队id
				edit: false, //是否编辑
				marketList: [],
				marketId: '', //选择搜索的卖场id
				type: '',
				mobile: '', //选择的用户
				partner_type:'shop',//订单类型
				orderList:[
					{
						name: '商品',
						id: 'shop'
					},
					{
						name: '产品包',
						id: 'pack'
					},
					{
						name: '施工队',
						id: 'builder'
					},
					{
						name: '设计师订单',
						id: 'designer'
					}
				],//订单类型
				valueTime: [],
				pickerOptions: {
				  disabledDate(time) {
				    return time.getTime() > Date.now() - 8.64e6;
				  },
				},
				startDate:'',
				endDate:'',
				orderStatus:[
					{
						'name':'已取消',
						'id':0
					},
					{
						'name':'待付款',
						'id':1
					},
					{
						'name':'待发货',
						'id':2
					},
					{
						'name':'待收货',
						'id':3
					},
					{
						'name':'已完成',
						'id':4
					},
					{
						'name':'已关闭',
						'id':5
					},
					{
						'name':'退货中',
						'id':6
					},
					
				]
			}
		},
		mounted(options) {
			let data = this.$route.query;
			this.steward_id = data.steward_id;
			this.choose_id = data.user_id;
			//团队列表
			this.getListAll();
			this.remoteMethod();
			this.getUserOrder(data.user_id)
		},

		methods: {

			handleSelect(item) {
				console.log(item);
			},
			// 获取卖场列表
			remoteMethod() {
				this.$http.post("/api/root/Market/marketList").then((res) => {
					if (res.code == 1) {
						this.marketList = res.data ? res.data : [];
					}
				});
			},
			// 选择订单类型
			selectOrder() {
				this.getUserOrder(this.choose_id);
			},

			handleAdd() {
				this.MadalTitle = "添加成员";
				this.visibleShow = true;
				this.getUserList();
			},
			//获取团队成员详情
			getListAll() {
				let params = {
					keyword: this.keyword,
					choose_id: this.choose_id,
					steward_id: this.steward_id,
					page: this.page,
					pagesize: this.pageSize
				}
				let that = this;
				that.$http.post('/api/root/steward/info', params).then(res => {
					if (res.code === 1) {
						var data = res.data
						that.userData = data
					} else {
						that.$message.error(res.msg)
					}
				}).catch(err => {
					that.$message.error(err.msg)
				})
			},
			// 图片上传
			handleRemove(file, fileList) {
				this.fileList = fileList;
			},
			handlePictureCardPreview(file) {
				this.dialogImageUrl = file.url;

				this.dialogVisible = true;
			},
			handleExceed(files, fileList) {
				this.$message.warning(`当前限制上传一张图片,请先删除原图片`);
			},
			handleAvatarSuccess(res, file, fileList) {
				this.fileList = fileList;
			},
			beforeAvatarUpload(file) {
				const isLt2M = file.size / 1024 / 1024 < 2;
				if (!isLt2M) {
					this.$message.error("上传商品图片大小不能超过 2MB!");
				}
				return isLt2M;
			},
			getHMS(time) {
				const hour = parseInt(time / 3600) < 10 ? '0' + parseInt(time / 3600) : parseInt(time / 3600)
				const min = parseInt(time % 3600 / 60) < 10 ? '0' + parseInt(time % 3600 / 60) : parseInt(time % 3600 / 60)
				const sec = parseInt(time % 3600 % 60) < 10 ? '0' + parseInt(time % 3600 % 60) : parseInt(time % 3600 % 60)
				return hour + ':' + min + ':' + sec
			},

			//添加商户
			addMerchant(id) {
				this.MadalTitle = "添加商户"
				this.merchantShow = true
				this.steward_id = id; //团队id

			},
			//删除团队成员
			deletes(steward_id, choose_id) {
				let params = {
					steward_id: steward_id, //管家团队id
					choose_id: choose_id, //用户id
				}
				let that = this;
				this.$confirm('是否删除团队成员', '提示').then(() => {
					that.$http.post('/api/root/steward/del', params).then(res => {
						if (res.code === 1) {
							that.$message.success('操作成功')
							that.getListAll();
						} else {
							that.$message.error(res.msg)
						}
					}).catch(err => {
						that.$message.error(err.msg ? err.msg : err.toString())
					})
				})
			},
			//团队用户订单
			getUserOrder(choose_id) {
				let params = {
					keyword:this.keyword,
					choose_id: choose_id,
					partner_type: this.partner_type,
					page: this.page,
					status:this.order_status,
					pageSize: this.pageSize,
					start_time:this.startDate,
					end_time:this.endDate
				}
				this.$http.post('/api/root/steward/stewardUserOrder', params).then(res => {
					if (res.code == 1) {
						let data = res.data.list;
						this.listData = data
						this.total=res.data.count
					}else{
						this.listData=[];
					}
				}).catch(err => {
					this.$message.error(err.msg ? err.msg : err.toString())
				})
			},
			// 选择时间
			selectTime() {
			  this.startDate = this.valueTime
			    ? this.$moment(this.valueTime[0]).format("yyyy-MM-DD 00:00:00")
			    : "";
			  this.endDate = this.valueTime
			    ? this.$moment(this.valueTime[1]).format("yyyy-MM-DD 23:59:59")
			    : "";
			  this.getUserOrder();
			},
			handleCancel() {
				this.MadalTitle = ''
				this.dialogVisible = false
				this.visibleShow = false
				this.fileList = [];
			},
			//隐藏弹窗
			storeCancel() {
				this.MadalTitle = ''
				this.merchantShow = false
			},

			// 选择状态
			selectStatus() {
				this.getUserOrder()
			},
			
			// 多选
			handlerCheckbox(i) {
				console.log(i);
				let arr = this.checkBoxAll;
				if (arr.includes(i)) {
					let index = arr.indexOf(i);
					if (index != -1) {
						arr.splice(index, 1);
						this.shelvesAlls.splice(index, 1);
						if (this.checkBoxAll.length !== this.tableList.length) {
							this.checkAll = false;
						}
					}
				} else {
					this.checkBoxAll.push(i);
					this.shelvesAlls.push(this.tableList[i].id);
					if (this.checkBoxAll.length == this.tableList.length) {
						this.checkAll = true;
					}
				};
				console.log(this.shelvesAlls);
			},
			// 全选与全不选
			handerCheckAll() {
				this.checkAll = !this.checkAll;
				let arr = this.tableList.length;
				this.checkBoxAll = [];
				this.shelvesAlls = [];
				if (this.checkAll) {
					for (let i = 0; i < arr; i++) {
						this.checkBoxAll.push(i);
					}
					this.checkBoxAll.map(v => {
						this.shelvesAlls.push(this.tableList[v].id.toString());;
					})
				} else {
					this.checkBoxAll = [];
					this.shelvesAlls = []
				}
				console.log(this.shelvesAlls);
			},
			//搜索
			handerSeach() {
				this.getUserOrder(this.choose_id)
			},

			handleSizeChange(val) {
				this.pageSize = val;
				this.getUserOrder(this.choose_id)
			},
			handleCurrentChange(val) {
				this.page = val;
				this.getUserOrder(this.choose_id)
			},
			formatDate(value) {
				let date = new Date(parseInt(value) * 1000);
				let y = date.getFullYear();
				let m = date.getMonth() + 1;
				m = m < 10 ? "0" + m : m;
				let d = date.getDate();
				d = d < 10 ? "0" + d : d;
				let h = date.getHours();
				h = h < 10 ? "0" + h : h;
				let minute = date.getMinutes();
				let second = date.getSeconds();
				minute = minute < 10 ? "0" + minute : minute;
				second = second < 10 ? "0" + second : second;
				return y + "-" + m + "-" + d + " " + h + ":" + minute + ":" + second;
			},
			//商户列表跳转
			teamDateils(id) {
				this.$router.push({
					name: "teamDateils",
					query: {
						id
					},
				});
			},
			goDetails(steward_id, user_id) {
				this.$router.push({
					name: "teamDateils",
					query: {
						steward_id,
						user_id
					},
				});
			}
		}
	}
</script>

<style lang="less" scoped>
	@import 'index.less';

	.partnerList_bottom_new_goods_screening {
		width: 100%;
		height: auto;
		display: flex;

		.searchBtn {
			max-width: 90px;
			min-width: 68px;
			height: 42px;
			line-height: 42px;
			background-color: #409EFF;
			margin-left: 5px;
			border: 0 none;
			outline: none;
			border-radius: 4px;
			color: #fff;
			cursor: pointer;
		}

		.inputBox {
			margin-right: 20px;
		}
	}

	.subnav {
		margin:10px 0 0 20px;
		.itemBlock {
			ul {
				li {
					list-style: none;
				}
			}
		}
		.searchBlock{
			display: flex;
			align-items: center;
		}
	}
</style>
<style>
	.ant-modal {
		width: 590px !important;
	}
</style>
